# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/27 13:49 
@Author  : ZhangShenao 
@File    : numerical_calculation.py 
@Desc    : 数值计算相关的内置函数
"""

# max()函数: 求最大值
max_value = max([1, 2, 3, 4, 5])
# max = 5
print(f'max = {max_value}')

# min()函数: 求最小值
min_value = min((1, 2, 3, 4, 5))
# min = 1
print(f'min = {min_value}')

# sum()函数: 求和
sum_value = sum([1, 2, 3, 4, 5])
# sum = 15
print(f'sum = {sum_value}')

# abs()函数: 求绝对值
abs1 = abs(-100)
# abs(-100) = 100
print(f'abs(-100) = {abs1}')
abs2 = abs(100)
# abs(100) = 100
print(f'abs(100) = {abs2}')

# pow()函数: 求幂
pow1 = pow(2, 3)
# pow(2, 3) = 8
print(f'pow(2, 3) = {pow1}')
pow2 = 2 ** 3
# pow(x,y) 等价于 x ** y
# 2 ** 3 = 8
print(f'2 ** 3 = {pow2}')

# bin()函数: 转换为二进制'0b',结果为str类型
bin1 = bin(10)
# bin(10) = 0b1010
print(f'bin(10) = {bin1}')
bin2 = bin(-100)
# bin(-100) = -0b1100100
print(f'bin(-100) = {bin2}')

# hex()函数: 转换为十六进制'0x',结果为str类型
hex1 = hex(10)
# hex(10) = 0xa
print(f'hex(10) = {hex1}')
hex2 = hex(-100)
# hex(-100) = -0x64
print(f'hex(-100) = {hex2}')

# round()函数: 对float类型的四舍五入,第二个参数为小数精度
r1 = round(3.1415926, 2)
# round(3.1415926, 2) = 3.14
print(f'round(3.1415926, 2) = {r1}')
r2 = round(99.99)
# round(99.99) = 100
print(f'round(99.99) = {r2}')
